/*
 * #%L
 * java model
 * %%
 * Copyright (C) 2009 - 2011 Stefan Isele
 * %%
 * All Rights Reserved.
 * This program is dual-licensed under the GNU General Public license
 * or a commercial license.
 * You may select to use one or the other of these licenses.
 * To obtain a commercial license please contact Stefan Isele at www.stefan-isele.de
 * Any modifications to this file must keep this entire header intact.
 * Redistribution, except as permitted by the selected license, is prohibited.
 * #L%
 */
package com.prefabware.jmodel.util;

import java.util.Collection;

import com.prefabware.jmodel.JArgument;
import com.prefabware.jmodel.JField;
import com.prefabware.jmodel.JMethod;
import com.prefabware.jmodel.JModifiers;
import com.prefabware.jmodel.JType;
import com.prefabware.jmodel.JTypeUtil;
import com.prefabware.jmodel.JVisibility;
import com.prefabware.jmodel.code.JBlock;
import com.prefabware.jmodel.code.JBlockEquals;
import com.prefabware.jmodel.code.JBlockHashCode;
import com.prefabware.jmodel.expression.JVariableBase;
import com.prefabware.jmodel.typefactory.TypeFactory;

public class JMethods {
public static JMethod newHashCode(JType type, Collection<JField> fields) {
	JMethod hashCode = JTypeUtil.newJMethod("hashCode", TypeFactory.int_, type, JModifiers.NONE, JVisibility.PUBLIC);
	JBlock block=new JBlockHashCode(type,fields);
	hashCode.add(block);
	return hashCode;
}
public static JMethod newEquals(JType declaringType, Collection<JField> fields, TypeFactory typeFactory) {
	JMethod equals = JTypeUtil.newJMethod("equals", TypeFactory.boolean_, declaringType, JModifiers.NONE, JVisibility.PUBLIC);
	JType objectType = typeFactory.getJType(Object.class);
	JVariableBase vdcl=JTypeUtil.newJVariable("other", objectType, equals.getDeclaration(), false);
	JArgument argument=new JArgument(vdcl);
	equals.getDeclaration().add(argument);
	JBlock block=new JBlockEquals(declaringType,fields);
	equals.add(block);
	return equals;
}
}
